package com.kris.dev2;


/**
 *  账户
 *
 *  implements Cloneable接口
 */
public class Account implements Cloneable {



    User user;

    long money;


    // 克隆对象
    public Object clone() throws CloneNotSupportedException {
        return super.clone();
    }


    /**
     * clone 对象
     * 在堆内存中 新建一块 和原对象所占对堆内存一样大小的地方
     * 把原对象拷贝一份到新的堆内存中
     *
     */
    public static void main(String[] args){

        User u = new User();
        u.name = "jack";
        u.age = 88;

        Account account = new Account();
        account.user = u;
        account.money = 100;

        System.out.println(account.hashCode());
        System.out.println(account.user.name);
        System.out.println("================");

        try {
            Account copy = (Account) account.clone();
            copy.user.name = "liqi";
            System.out.println(copy.hashCode());
            System.out.println("复制后："+copy.user.name);
            System.out.println("复制后："+copy.money);
            System.out.println("account:"+account.user.name);

        } catch (CloneNotSupportedException e) {
            e.printStackTrace();
        }

    }



}
